package com.wdc.deliveryrobot.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wdc.deliveryrobot.R;

import java.util.List;

/**
 * @Author: tianHuiDa
 * @Date: 2024/11/17
 * @Description: 点位详情
 */
public class CruiseMoreAdapter extends RecyclerView.Adapter<CruiseMoreAdapter.ViewHolder> {

    private List<String> listSelect;

    public OnItemClickListener listener;

    public interface OnItemClickListener{
        void delete(String name);
    }
    public CruiseMoreAdapter(List<String> listSelect){
        this.listSelect = listSelect;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.point_more, parent, false);
        return new CruiseMoreAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String name = listSelect.get(position);
        holder.textView.setText(name);
        if (position == listSelect.size() - 1){
            //最后一个
            holder.imageView.setVisibility(View.GONE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null){
                    listener.delete(name);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return listSelect.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView textView;
        public ImageView imageView;

        public ViewHolder(View itemView){
            super(itemView);
            textView = itemView.findViewById(R.id.text);
            imageView = itemView.findViewById(R.id.next_more);
        }
    }

    public void setListSelect(List<String> listSelect){
        this.listSelect = listSelect;
    }
}
